Print one to n


Posted by Christy on 2022-04-19

Description: Write a function that accepts a number n and print number one to n

function print(n) {

}

print(1);
// 1

print(3);
// 1
// 2
// 3

print(9);
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9

Answer:

function print(n) {
  for (let i = 1; i <= n; i++) {
    console.log(i);
  }
}

print(1);
print(3);
print(9);









Related Posts

鏈結串列(Linked List)& 陣列(Array)

鏈結串列(Linked List)& 陣列(Array)

關於 React 小書:dangerouslySetInnerHTML & style

關於 React 小書:dangerouslySetInnerHTML & style

從 Flux 與 MVC 的差異來簡介 Flux

從 Flux 與 MVC 的差異來簡介 Flux


Comments